﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MethodWorx.Core.DomainModel
{
    public abstract class QueryableRepository<T> : Repository<T>
        where T : AggregateRoot
    {
        protected IQueryable<T> source;

        public QueryableRepository(IQueryable<T> source)
        {
            if (source == null)
                throw new ArgumentException("source");

            this.source = source;
        }

        public override IEnumerable<T> All()
        {
            return this.source.ToList();
        }

        public override IQueryable<T> Query()
        {
            return this.source;
        }

        public override T this[Guid id]
        {
            get
            {
                return this.source.FirstOrDefault(s => s.Id == id);
            }
        }

        public override bool Contains(T entity)
        {
            return this.source.Contains(entity);
        }
    }
}
